package array

func Map[T any, R any](array []T, mapper func(T) R) []R {
	result := make([]R, 0, len(array))
	for _, v := range array {
		result = append(result, mapper(v))
	}
	return result
}

func Reduce[T any, R any](array []T, reducer func(R, T) R, initialValue R) R {
	result := initialValue
	for _, v := range array {
		result = reducer(result, v)
	}
	return result
}

func Filter[T any](array []T, predicate func(T) bool) []T {
	result := make([]T, 0, len(array))
	for _, v := range array {
		if predicate(v) {
			result = append(result, v)
		}
	}
	return result
}

func ForEach[T any](array []T, callback func(T)) {
	for _, v := range array {
		callback(v)
	}
}

func Some[T any](array []T, predicate func(T) bool) bool {
	for _, v := range array {
		if predicate(v) {
			return true
		}
	}
	return false
}
func Every[T any](array []T, predicate func(T) bool) bool {
	for _, v := range array {
		if !predicate(v) {
			return false
		}
	}
	return true
}
